<?php 
/* P3(c)

******************************************************************************
                                                                                      
                         __                                                        
                        /__)                                                       
                       /__        P3 - moving Technologie            
                        __)                                                          
                        __)                                                          
                                                                                        
                                                                                        
       Copyright 2009 by p3.co.at                                                                                 
                                                                                        
       visit www.p3.co.at to get more Informations 
       about Teriko - Betriebsdatenerfassung                                                                                 
       - it's not allowed to change this scripts
       - it's not allowed to remove this copyright-tag

       -- you can download the complete license   
          under http://www.teriko.org

 (c) by Patrik Pfaffenbauer and P3 (http://www.p3.co.at)

 | Programname: P3.Teriko
 | Authtor: P3.Verein
 | Coder: Patrik Pfaffenbauer
 | Version: 0.1

 | Change Index
 |_____________________________________________
 |                                             |
 |4.3.2010 Erstellung | Patrik Pfaffenbauer    |
 |_____________________________________________|

******************************************************************************

P3(c) */ 

class Panel
{
	var $rowOpen = false;
	var $firstRow = true;
	var $type;
	var $formname = "adminForm";
	var $tableclass = "adminform";
	var $tabid = 0;
	var $tabOpen = false;
	var $funcOnClose = true;
	
	public function Panel($tableclass = "adminform")
	{
		$this->tableclass = $tableclass;
		echo '
		<form action="index.php?s='.$_GET['s'].'" method="post" name="'.$this->formname.'">
			<table class="'.$this->tableclass.'">
			<tr><td width="20%" colspan="3" style="font-weight:bold; color:grey;">'.$GLOBALS['lang']->GetLanguage("Common", "data").':</td>
			<td style="font-weight:bold; color:grey;"></td>
			</tr>';
		
		$this->firstRow = false;
	}
	
	public function AddRow()
	{
		if($rowOpen)
		{
			echo '</tr>';
		}
		
		echo '<tr>';
		
		$rowOpen = true;
	}
	
	public function AddTabView($header, $content)
	{	
		if(!$this->tabOpen)
		{
			echo '<tr><td colspan="100%">';
			echo '<div id="tabView'.$this->tabid.'">';
			
			$this->tabOpen = true;
		}
		
		echo '<h4 title="'.$header.'">'.$header.'</h4>
				<div>';	
	}
	public function CloseTab()
	{
		echo '</div>';
	}
	public function CloseTabView()
	{		
		$this->tabOpen = false;
		echo '</div></td></tr>';
		echo '
		
		<script type="text/javascript">
			new SimpleTabs(\'tabView'.$this->tabid.'\', {selector: \'h4\'});
		</script>
		
		';
		$this->tabid++;
	}
	
	private function AddFunctions()
	{
		echo '<center><td valign="top" colspan="2" align="center">';
		
		if(!isset($this->type))
		{
			if($_POST['action'] == "add")
				$this->type = "save";
			else
				$this->type = "update";
		}

		echo ' <table class="toolbar2" style="margin-left:25%;">
					<tr>
						<td class="button" id="toolbar-save">
							<a href="javascript::void(0);" onclick="Submitform(\''.$type.'\');" class="toolbar">
							<span class="icon-32-save" title="'.$GLOBALS['lang']->GetLanguage("Common", "save").'">
							</span>
							'.$GLOBALS['lang']->GetLanguage("Common", "save").'
							</a>
						</td>
						<td>
							<a href="javascript::void(0);" onclick="Submitform(\'cancel\');" class="toolbar">
							<span class="icon-32-cancel" title="'.$GLOBALS['lang']->GetLanguage("Common", "abort").'">
							</span>
							'.$GLOBALS['lang']->GetLanguage("Common", "abort").'
							</a>
						</td>
					</tr>
				
					</table>
	
				</td></center>';		
		
		if($this->firstRow)
			$this->firstRow = false;
	}
	
	public function AddTextBox($name, $text, $value, $maxLength = 45, $size = 30)
	{			
		echo '
		<td valign="top">
			<label for="'.$name.'">
				<strong>'.$text.':</strong>
			</label>
		</td>
		<td><input class="inputbox" type="text" name="'.$name.'" id="'.$name.'" size="'.$size.'" maxlength="'.$maxLength.'" value="'.$value.'" />
		</td>';
		
		if($this->firstRow)
			$this->AddFunctions();
	}
	
	public function AddMandatoryTextBox($name, $text, $value, $maxLength = 45, $size = 30)
	{			
		echo '
		<td valign="top">
			<label for="'.$name.'">
				<strong>'.$text.':</strong>
			</label>
		</td>
		<td><input class="inputbox" type="text" name="'.$name.'" id="'.$name.'" size="'.$size.'" maxlength="'.$maxLength.'" value="'.$value.'" /><strong>*</strong>
		</td>';
		
		if($this->firstRow)
			$this->AddFunctions();
	}
	
	public function AddText($text)
	{
		echo '
		<td width="100" valign="top">
			<label for="error">
				<strong>Error:</strong>
			</label>
		</td>
		<td width="100%">'.$text.'</td>';
	}
	
	public function AddText2($header, $text)
	{
		echo '
		<td width="100" valign="top">
			<label for="'.$header.'">
				<strong>'.$header.':</strong>
			</label>
		</td>
		<td width="100%">'.$text.'</td>';
	}
	
	public function AddTextArea($name, $text, $value, $cols, $rows)
	{
		echo '
		<td width="100" valign="top">
			<label for="'.$name.'">
				<strong>'.$text.':</strong>
			</label>
		</td>
		<td><textarea name="'.$name.'" id="'.$name.'" cols="'.$cols.'" rows="'.$rows.'">'.$value.'</textarea>
		</td>';
	}
	
	public function AddCKEditor($name, $text, $value, $width, $height)
	{
		echo '
		<td width="100" valign="top">
			<label for="'.$name.'">
				<strong>'.$text.':</strong>
			</label>
		</td>
		<td><textarea name="'.$name.'" id="'.$name.'" cols="'.$cols.'" rows="'.$rows.'">'.$value.'</textarea>
		</td>';
		
		echo '
		<script type="text/javascript">
			CKEDITOR.replace(\''.$name.'\');
		</script>
		';
	}
	
	public function AddTextBoxTooltip($name, $text, $value,$maxLength = 45, $size = 30, $tooltip)
	{
				echo '
		<td width="100" valign="top">
			<label for="'.$name.'">
				<strong>'.$text.':</strong>
			</label>
		</td>
		<td>
			<input class="inputbox" type="text" name="'.$name.'" id="'.$name.'" size="'.$size.'" maxlength="'.$maxLength.'" value="'.$value.'" />	
			<span class="editlinktip hasTip" title="'.$tooltip.'" style="text-decoration: none; color: #333;">
				<img src="/joomla/includes/js/ThemeOffice/tooltip.png" border="0" alt="Tooltip"/>
			</span>		
		</td>
	';
		if($this->firstRow)
			$this->AddFunctions();
	}
	
	public function AddDateTextBox($name, $text, $value)
	{
		echo '
		<td valign="top">
			<label for="'.$name.'">
				<strong>'.$text.':</strong>
			</label>
		</td>
		<td>
			<input type="hidden" id="DPC_TODAY_TEXT" value="'.$GLOBALS['lang']->GetLanguage("Calender", "today").'">
			<input type="hidden" id="DPC_BUTTON_TITLE" value="'.$GLOBALS['lang']->GetLanguage("Calender", "open").'">
			<input type="hidden" id="DPC_MONTH_NAMES" value="'.$GLOBALS['lang']->GetLanguage("Calender", "months").'">
			<input type="hidden" id="DPC_DAY_NAMES" value="'.$GLOBALS['lang']->GetLanguage("Calender", "days").'">
		<input type="text" name="'.$name.'" id="DPC_'.$name.'_'.$GLOBALS['lang']->GetLanguage("Calender", "format").'" value="'.$value.'"/> 
		<a href="#" onclick="InsertDate(\'DPC_'.$name.'_'.$GLOBALS['lang']->GetLanguage("Calender", "format").'\');">Heute</a>
		</td>';
		
		if($this->firstRow)
			$this->AddFunctions();
	}

	public function AddHidden($name, $value)
	{
		echo '<input type="hidden" name="'.$name.'" value="'.$value.'" />';
		if($this->firstRow)
			$this->AddFunctions();
	}
	
	public function AddComboBox($name, $text, $value,  $table, $id, $desc)
	{
		$res = $GLOBALS['db']->Query("SELECT ".$id.",".$desc." FROM ".$table);
		
		echo '
		<td width="100" valign="top">
			<label for="'.$name.'">
				<strong>'.htmlentities($text).':</strong>
			</label>
		</td>
		<td>
			<select name="'.$name.'">';
		
		while($line = $GLOBALS['db']->FetchArray($res))
		{
			if($value != "")
			{
				if($value == $line[0])
				{
					echo '<option value="'.$line[0].'" selected>'.$line[1].'</option>';	
				}
				else
				{
					echo '<option value="'.$line[0].'">'.$line[1].'</option>';	
				}
			}
			else
			{
				echo '<option value="'.$line[0].'">'.$line[1].'</option>';	
			}
		}
		echo '</select></td>';
		if($this->firstRow)
			$this->AddFunctions();
	}

	public function AddCheckBox($name, $text, $value)
	{
		echo '
		<td width="100" valign="top">
			<label for="'.$name.'">
				<strong>'.htmlentities($text).'</strong>
			</label>
		</td>
		<td>';
				
		if($value)
		{
			echo '<input type="checkbox" name="'.$name.'" value="'.$text.'" checked />';
		}
		else
		{
			echo '<input type="checkbox" name="'.$name.'" value="'.$text.'" />';
		}
		
		echo '</td>';
		if($this->firstRow)
			$this->AddFunctions();
	}
	
	public function Close()
	{
		if($this->funcOnClose)
		{
			$this->AddRow();
			$this->AddText2($GLOBALS['lang']->GetLanguage("Common", "note"), $GLOBALS['lang']->GetLanguage("Panel", "mandatoryField"));
			
			echo '<tr>';
			$this->AddFunctions();
			echo '</tr></table></form>';
		}
		else
		{
			echo '</table></form>';
		}
	}
	
	public function CloseWithoutForm()
	{
		$this->AddRow();
		$this->AddText2($GLOBALS['lang']->GetLanguage("Common", "note"), $GLOBALS['lang']->GetLanguage("Panel", "mandatoryField"));
		
		echo '<tr>';
		$this->AddFunctions();
		echo '</tr></table>';
	}
	
	public function CloseForm()
	{
		echo '</form>';
	}
}

?>